import type { Router } from 'vue-router';
import { setRouteEmitter } from '@/utils/route-listener';
import setupUserLoginInfoGuard from './userLoginInfo';
import setupPermissionGuard from './permission';
import NProgress from 'nprogress'; // progress bar

function setupPageGuard(router: Router) {
  router.beforeEach(async (to, from) => {
    // console.log('from.path', from.path);

    // if (from.path.includes('/app/approval')) {
    //   history.replaceState({ back: from.path }, to.name, '');
    // }
    // emit route change
    setRouteEmitter(to);
  });
}

export default function createRouteGuard(router: Router) {
  // 按顺序执行
  setupPageGuard(router);
  setupUserLoginInfoGuard(router);
  setupPermissionGuard(router);
}
